﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Card.Web.Member
{
    public partial class OrderDetail : MemberBase
    {
        #region
        /// <summary>
        /// 订单编号
        /// </summary>
        public string OrderID
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["oid"]))
                {
                    return Request.QueryString["oid"];
                }
                return string.Empty;
            }
        }

        public Entity.Order Order = null;
        #endregion

        #region
        protected void Page_Load(object sender, EventArgs e)
        {
            this.DoInit();
        }

        protected override void OnInit(EventArgs e)
        {
            this.btnSubmit.Click += new EventHandler(btnSubmit_Click);
            base.OnInit(e);
        }

        void btnSubmit_Click(object sender, EventArgs e)
        {
            Response.Redirect(string.Format("ConfirmOrder.aspx?oid={0}", this.OrderID));
        }
        #endregion

        #region
        private void DoInit()
        {
            Entity.Order order = BLL.OrderManager.GetEntity(this.OrderID, this.Passport);
            if (order != null
                && order.UserID == this.Passport.UserID)
            {
                if (string.Compare(order.OrderStatusCode, CONST.ORDER_SATTUS.WAIT_PAY, true) == 0)
                {
                    this.btnSubmit.Visible = true;
                }
                else
                {
                    this.btnSubmit.Visible = false;
                }
                BAF.Entity.LookupValue lookUpSipping = Common.LookUpCache.GetLookupValue(CONST.LOOKUP_TYPE.SIPPING_DATE, order.SippingDateCode);
                if (lookUpSipping != null)
                {
                    this.ltlSippingDate.Text = lookUpSipping.Value;
                }

                BAF.Entity.LookupValue lookUpPayment = Common.LookUpCache.GetLookupValue(CONST.LOOKUP_TYPE.PAYMENT_METHOD, order.PaymentMethodCode);
                if (lookUpPayment != null)
                {
                    this.ltlPayment.Text = lookUpPayment.Value;
                }

                this.Order = order;
                this.ltlRemark.Text = order.Remark;

                this.rptList.DataSource = BLL.OrderItemManager.GetItemList(OrderID, this.Passport);
                this.rptList.DataBind();
            }
            else
            {
                Response.Redirect("/");
            }
        }
        #endregion
    }
}
